package com.tarena.lbs.message.rpc;

import com.tarena.lbs.common.principle.UserPrinciple;
import com.tarena.lbs.common.utils.AuthenticationContextUtils;
import com.tarena.lbs.message.api.MessageApi;
import com.tarena.lbs.message.api.pojo.dto.ActivityDto;
import com.tarena.lbs.message.pojo.po.MessageSearch;
import com.tarena.lbs.message.dao.repository.MessageESRepository;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@DubboService
@RequiredArgsConstructor
public class MessageApiImpl implements MessageApi {
    private final MessageESRepository messageESRepository;
    @Override
    public void sendActivity(ActivityDto activityDto) {
        UserPrinciple user = AuthenticationContextUtils.get();
        MessageSearch messageSearch = new MessageSearch();
        messageSearch.setActivityId(activityDto.getId());
        messageSearch.setActivityPic(activityDto.getActivityPic());
        messageSearch.setType(activityDto.getActivityType());
        messageSearch.setMsgTitle(activityDto.getActivityName());
        messageSearch.setContent(activityDto.getDescribes());
        messageSearch.setType(1);
        messageSearch.setUserId(user.getId());
        messageSearch.setCreateAt(new Date());
        messageESRepository.save(messageSearch);
    }
}
